package ua.org.nuos.sdms.clientgui.client.components.factory;

import com.vaadin.ui.*;
import com.vaadin.ui.themes.ChameleonTheme;

import java.util.Locale;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 26.02.12
 * Time: 16:57
 * To change this template use File | Settings | File Templates.
 */
public class CustomFieldFactory extends DefaultFieldFactory {

    protected TextField createTextField(String caption, boolean isRequired) {
        TextField tf = new TextField();
        tf.setHeight("25");
        tf.setRows(0);
        initAbstractField(tf, caption, isRequired);
        tf.setNullRepresentation("");
        return tf;
    }

    protected TextArea createTextAreaField(String caption, boolean isRequired) {
        TextArea ta = new TextArea();
        ta.setNullRepresentation("");
        initAbstractField(ta, caption, isRequired);
        ta.setNullRepresentation("");
        return ta;
    }

    protected DateField createDateField(String caption, boolean isRequired) {
        PopupDateField df = new PopupDateField();
        df.setLocale(new Locale("uk_UK"));
        df.setResolution(PopupDateField.RESOLUTION_DAY);
        initAbstractField(df, caption, isRequired);
        df.setSizeUndefined();
        return df;
    }

    protected Label createLabel(String caption) {
        Label l = new Label();
        l.setCaption(caption);
        l.setWidth("100%");
        return l;
    }

    protected CheckBox createCheckBox(String caption, boolean isRequired) {
        CheckBox cb = new CheckBox();
        initAbstractField(cb, caption, isRequired);
        return cb;
    }

    protected void initAbstractField(AbstractField af, String caption, boolean isRequired) {
        af.setCaption(caption);
        af.setRequired(isRequired);
        af.setRequiredError("Поле \"" + caption + "\" является обязательным.");
        af.setWidth("100%");
        af.setImmediate(true);
    }

}
